/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.bean.TOrder;
/**在线预定订单
 * @Author：李智深
 * @Date：2012-03-22
 */
public class OrderHistoryModel extends AbstractTableModel{

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	
	public OrderHistoryModel(){
		columns.add("订单编号");
		columns.add("用户编号");
		columns.add("配送地址");
		columns.add("支付状态");
		columns.add("配送方式");
		columns.add("总金额");
		columns.add("已付金额");
		columns.add("销售人");
		columns.add("操作人");
		columns.add("订单状态");
		columns.add("操作");
	}

	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	
	//获取列对应的类型
	public Class getColumnClass(int column){
		return column == (columns.size()-1) ? ImageIcon.class : Object.class;
	}
	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	
	
	
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}


	public void setRowData(List<TOrder> tOrderList) {
		rowdatas.clear();
		if(tOrderList!=null&&tOrderList.size()!=0){
			for(int i=0;i<tOrderList.size();i++){
				TOrder tOrder=tOrderList.get(i);
				List<Object> row=new Vector<Object>();
				
				//订单编号
				row.add(tOrder.getOrderID());
				//用户编号
				if(tOrder.getTUser()!=null){
					row.add(tOrder.getTUser().getUserID());
				}else{
					row.add("无");
				}
				//配送地址
				if(tOrder.getTSendInfo()!=null&&tOrder.getTSendInfo().getLocation()!=null){
					row.add(tOrder.getTSendInfo().getLocation());
				}else{
					row.add("");
				}
				//支付状态
				if(tOrder.getPayStatus()==ApplicationContext.PLAY_STATUS_NO){
					row.add(ApplicationContext.PLAY_STATUS_NO_TEXT);
				}else{
					row.add(ApplicationContext.PLAY_STATUS_YES_TEXT);
				}
				//配送方式
				if(tOrder.getSendWay()==ApplicationContext.ORDER_SENDWAY_MODT1){
					row.add(ApplicationContext.ORDER_SENDWAY_MODT1_TEXT);
				}else{
					row.add(ApplicationContext.ORDER_SENDWAY_MODT2_TEXT);
				}
				//总金额
				row.add(tOrder.getTotalAmount());
				//已付金额
				row.add(tOrder.getPayedAmount());
				//销售人
				row.add(tOrder.getSaler());
				//操作人
				row.add(tOrder.getOperator());
				//订单状态
				if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS01){
					row.add(ApplicationContext.ORDER_STATUS01_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS02){
					row.add(ApplicationContext.ORDER_STATUS02_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS03){
					row.add(ApplicationContext.ORDER_STATUS03_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS04){
					row.add(ApplicationContext.ORDER_STATUS04_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS05){
					row.add(ApplicationContext.ORDER_STATUS05_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS06){
					row.add(ApplicationContext.ORDER_STATUS06_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS07){
					row.add(ApplicationContext.ORDER_STATUS07_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS11){
					row.add(ApplicationContext.ORDER_STATUS11_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS12){
					row.add(ApplicationContext.ORDER_STATUS12_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS13){
					row.add(ApplicationContext.ORDER_STATUS13_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS14){
					row.add(ApplicationContext.ORDER_STATUS14_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS15){
					row.add(ApplicationContext.ORDER_STATUS15_TEXT);
				}else if(tOrder.getStatus()==ApplicationContext.ORDER_STATUS16){
					row.add(ApplicationContext.ORDER_STATUS16_TEXT);
				}else {
					row.add(ApplicationContext.ORDER_STATUS17_TEXT);
				}
				row.add("");
				rowdatas.add(row);
			}
		}
	}
}
